import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-07-17
 * Time: 15:30
 */
public class JDBCDelete {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource=new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("123456");

        Connection connection= dataSource.getConnection();

        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入姓名");
        String name=scanner.next();

        String sql="delete from student where student_name=?";

        PreparedStatement statement=connection.prepareStatement(sql);
        statement.setString(1,name);
        System.out.println(statement);

        int n=statement.executeUpdate();
        System.out.println("n="+n);

        statement.close();
        connection.close();
    }
}
